<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateUserCoursesTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('user_courses', function (Blueprint $table) {
            $table->increments('id');
            $table->string('order_sn', 32);
            $table->string('courseable_type', 50);
            $table->string('courseable_id', 50);
            $table->integer('user_id');
            $table->tinyInteger('pay_status')->default(0);            // 0 未付款 1 已支付 3 已退款 4 已拒绝退款
            $table->string('pay_code', 32)->nullable();        //ALIPAY, COD(货到付款), COUPON, OTHER, WXPAY
            $table->string('pay_name', 32)->nullable();
            $table->timestamp('paid_at')->nullable();
            $table->integer('integral')->default(0);
            $table->decimal('integral_price')->default(0);             // 使用积分抵扣
            $table->decimal('discount')->default(0);                   // 折扣
            $table->decimal('total_amount')->default(0);               // 订单总价
            $table->decimal('order_amount')->default(0);               // 应支付金额
            $table->timestamps();
            $table->softDeletes();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('user_courses');
    }
}
